class AccountUI extends UIBase {
	private img_tittle:eui.Image;
	private btn_close:BaseButton;
	private img_icon_1:eui.Image;
	private lb_award_1:eui.Label;
	private img_icon_2:eui.Image;
	private lb_award_2:eui.Label;
	private lb_mul:eui.Label;
	private btn_mul:BaseButton;
	private btn_next:eui.Label;
	private lb_percent:eui.Label;

	public constructor(data?) {
		super('AccountView',data);
	}

	public init()
	{
		super.init(true);
		let gold = this.data.gold;
        let diamond = this.data.diamond;
		let multiple = this.data.multiple;
		let percent = this.data.percent;
		this.lb_mul.text = `x${multiple}`;
		if(percent != 0)
		{
			//有武器加成
			this.lb_percent.visible = true;
			percent *= 100;
			let value = Math.abs(percent);
			if(percent < 0)
			{
				let desc = StringUtil.getColorString(`${value}%`,0xed4747);
				this.lb_percent.textFlow = StringUtil.getTextFlow('收益减少'+desc);
			}
			else
			{
				let desc = StringUtil.getColorString(`${value}%`,0x019616);
				this.lb_percent.textFlow = StringUtil.getTextFlow('收益增加'+desc);
			}
		}
		this.btn_next.textFlow = StringUtil.getTextFlow('<u>下一关</u>');
		if(gold)
		{
			this.lb_award_1.text = `x${gold}`;
			this.img_icon_1.source = 'icon_gold';
			RoleCache.instance().myMoney += parseInt(gold);
		}
		if(diamond)
		{
			this.lb_award_2.text = `x${diamond}`;
			this.img_icon_2.source = 'icon_diamond';
			RoleCache.instance().myDiamond += parseInt(diamond);
		}
		SoundManager.instance().playSound('win_mp3', 1);
	}

	public addEvent()
	{
		this.btn_close.addTapHandler(this.close, this);
		this.btn_mul.addTapHandler(this.vedioHandle, this);
		this.btn_next.addEventListener(egret.TouchEvent.TOUCH_TAP, this.nextCustom, this);
	}

	public vedioHandle()
	{
		let platform = egret.Capabilities.os;
        if(platform == 'Windows PC')
		{
			this.getMore();
			return;
		}
		
		let self = this;
		let Success_call = function()
        {  
			// self.isMul = true;
			// self.close();
			self.getMore();
        };
        let Error_call = function()
        {  
			WeChatgGameManager.instance().showModal('系统提示','观看完整视频才能收益翻倍哦~',true, '立即观看',call, this);
        };
		let call:Function = function()
		{
			WeChatgGameManager.instance().showVideoAd(GameConst.adList.other_vedio, Success_call, Error_call, this);
		}
        WeChatgGameManager.instance().showVideoAd(GameConst.adList.other_vedio, Success_call, Error_call, this);
	}

	public getMore()
	{
		let data = {
			multiple:this.data.multiple,
			coin:this.data.gold,
			diamond:this.data.diamond
		}
		AccountPrase.instance().mul_account(data);
	}

	public nextCustom()
	{
		this.close();
	}

	public close()
	{
		this.remove(1);
		let logic:GameUI = UIManager.instance().getLogicByName(UIConst.GAME_UI) as GameUI;
		if(logic)
		{
			logic.nextCustoms(true);
		}
		GameUtil.dispatchEvent(EventConst.RESOURCE_CHANGE);
	}

	public removeEvent()
	{
		this.btn_close.removeTapHandler();
		this.btn_mul.removeTapHandler();
		this.btn_next.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.nextCustom, this);
	}

	public clear()
	{
		super.clear();
	}
}